package com.jinhongone.pattern.behavior.responsibility;

/**
 * @author jinho
 * @className Handler
 * @description 抽象处理类
 * @date 2025/4/14 10:26
 */
public abstract class Handler {

    //请假天数临界值(常量)
    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;

    //领导处理请假天数区间
    private int numStart;
    private int numEnd;

    //下一节点处理器
    private Handler nextHandler;

    //构造函数，赋予领导处理天数区间
    //设置领导处理假期天数初始值，上不封顶
    public Handler(int numStart) {
        this.numStart = numStart;
    }

    //设置领导处理假期天数范围
    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    //设置下一节点
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    //提交请假
    public void submit(LeaveRequest leave) {
        if (leave.getDays() >= this.numStart) {
            handleLeave(leave); //本级领导处理
            //存在下级处理器且请假天数大于本级领导权限天数
            if (nextHandler != null && leave.getDays() > this.numEnd) {
                this.nextHandler.submit(leave);
            } else {
                System.out.println("请假流程处理完毕");
            }
        } else {
            System.out.println("请假天数为" + leave.getDays() + ",不予处理");
        }
    }

    //各级领导处理逻辑
    public abstract void handleLeave(LeaveRequest leave);
}
